package com.lkj.consumer;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Consumer_WorkQueues1 {

    public static void main(String[] args) throws IOException, TimeoutException {

        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("192.168.1.84");
        factory.setPort(5672);
        factory.setVirtualHost("/lkj");
        factory.setUsername("lkj");
        factory.setPassword("lkj");

        Connection connection = factory.newConnection();

        Channel channel = connection.createChannel();
        channel.basicQos(1);
        channel.queueDeclare("work_queues",true,false,false,null);

        Consumer consumer = new DefaultConsumer(channel) {

            @Override
            public void handleDelivery(String s, Envelope envelope, AMQP.BasicProperties basicProperties, byte[] bytes) throws IOException {
                System.out.println(new String(bytes));
            }
        };

        channel.basicConsume("work_queues",false,consumer);
    }
}
